#include <string>
#include "libevent_cpp/include/include_all.h"
#include "svr_util/include/su_mgr.h"
#include "svr_util/include/single_progress.h"
#include "svr_util/include/log_file.h"
#include "../com/unit_test.h"
#include "acc_driver/include/acc_driver.h"

using namespace std;
using namespace su;
using namespace lc;
using namespace proto;

class EchoServer : public IADFacade
{
public:
	void Start();
	virtual void OnRegOK(uint32_t accId) override;
	//接收client请求认证的包. 
	//@tmpSnId 临时会话Id，未认证
	virtual void OnRevVerifyReq(const proto::SessionId& tmpSnId, uint32 cmd, const std::string& msg) override;
	//接收client认证后的消息包到
	virtual void OnRevClientMsg(const proto::Session& session, uint32 cmd, const std::string& msg) override;
};

void EchoServer::Start()
{
	UNIT_INFO("EchoServer Start");
	std::vector<AccAddr> vec_addr;
	AccAddr addr;
	addr.ip = "127.0.0.1";
	addr.port = 54831;//连接 acc内部地址
	vec_addr.push_back(addr);

	AdFacadeInitData d;
	d.vecAccAddr = vec_addr;
	d.mainCmd = 1;
	d.svrId = 1;
	d.isVerifySvr = true;
	ADFacadeMgr::Ins().Init(*this, d);
}

void EchoServer::OnRegOK(uint32_t accId)
{
	//向acc注册成功
	UNIT_INFO("EchoServer reg ok");
}

void EchoServer::OnRevVerifyReq(const proto::SessionId& tmpSnId, uint32 cmd, const std::string& msg)
{
	//接收client请求登录消息,无条件通过，原消息号返回
	UNIT_INFO("rev verfiy. cmd=%d", cmd);
	ADFacadeMgr::Ins().NtfVerifyRet(tmpSnId, true);
	tmpSnId.SendToClient(cmd, "verify_ok");
}

void EchoServer::OnRevClientMsg(const proto::Session& session, uint32 cmd, const std::string& msg)
{
	//接收client 请求消息
	UNIT_INFO("echo msg. cmd=%x", cmd);
	session.SendToClient(cmd, msg);
}

int main(int argc, char* argv[])
{
	EchoServer svr;
	svr.Start();

	EventMgr::Ins().Dispatch();

	return 0;
}

